#pragma once

#include "DXAMLCommon.h"
#include "xamlruntime.h"

#include "XamlSchemaContext.h"
#include "CDependencyProperty.h"
#include "XamlServiceProviderContext.h"
#include "IPALUri.h"
#include "XamlCommonServiceProviderContext.h"

class XamlNativeRuntime :
	public XamlRuntime
{

private: 
	XamlNativeRuntime(const xshared_ptr<XamlSchemaContext> & inXamlSchemaContext);
public: 
	static HRESULT Create(const xshared_ptr<XamlSchemaContext> & inXamlSchemaContext, xshared_ptr<XamlRuntime> & outXamlRuntime);

	virtual HRESULT CreateInstance(const struct XamlTypeToken & inXamlType, xshared_ptr<XamlQualifiedObject> & qo);
	virtual HRESULT CreateFromValue(class xshared_ptr<XamlServiceProviderContext> inServiceContext, const struct XamlTypeToken & inTextSyntaxToken, const xshared_ptr<XamlQualifiedObject> & qoValue, const struct XamlPropertyToken & inProperty, const struct XamlTypeToken & inType, const xshared_ptr<XamlQualifiedObject> & qoRootInstance, xshared_ptr<XamlQualifiedObject> & qo);
	virtual HRESULT CreateFromXmlText(const struct XamlTypeToken & inXamlType, const xshared_ptr<CXString> & inText, xshared_ptr<XamlQualifiedObject> & qo);
	virtual HRESULT GetValue(const xshared_ptr<XamlQualifiedObject> & qoObj, const struct XamlPropertyToken & inProperty, xshared_ptr<XamlQualifiedObject> & outValue);
	virtual HRESULT SetValue(const struct XamlTypeToken & inType, const xshared_ptr<XamlQualifiedObject> & inObj, const struct XamlPropertyToken & inProperty, const xshared_ptr<XamlQualifiedObject> & inValue, XBOOL bAllowEvents, XBOOL bBindTemplates);
	virtual HRESULT Add(const xshared_ptr<XamlQualifiedObject> & qoCollection, const struct XamlPropertyToken & inCollectionProperty, const xshared_ptr<XamlQualifiedObject> & inValue, const struct XamlTypeToken & valueXamlType);
	virtual HRESULT AddToDictionary(const xshared_ptr<XamlQualifiedObject> & collection, const struct XamlPropertyToken & property, const xshared_ptr<XamlQualifiedObject> & value, const xshared_ptr<XamlQualifiedObject> & key);
	virtual HRESULT CallProvideValue(const xshared_ptr<XamlQualifiedObject> & qoMarkupExtension, const xshared_ptr<XamlCommonServiceProviderContext> & spServiceProviderContext, xshared_ptr<XamlQualifiedObject> & qo);
	virtual HRESULT InitializationGuard(const xshared_ptr<XamlType> & spXamlType, const xshared_ptr<XamlQualifiedObject> & qoInstance, XBOOL fInitializing);
	virtual HRESULT SetUriBase(const xshared_ptr<XamlType> & spXamlType, const xshared_ptr<XamlQualifiedObject> & qoInstance, class xref_ptr<IPALUri> spBaseUri);
	virtual HRESULT SetConnectionId(const xshared_ptr<XamlQualifiedObject> & qoComponentConnector, const xshared_ptr<XamlQualifiedObject> & qoConnectionId, const xshared_ptr<XamlQualifiedObject> & qoTarget);

	static HRESULT GetTypeTokenForDO(CDependencyObject * pdo, struct XamlTypeToken & ttTypeToken);
protected: 
	HRESULT GetCore(CCoreServices * * ppCore);
	HRESULT GetSchemaContext(xshared_ptr<XamlSchemaContext> & outSchemaContext);
private: 
	HRESULT CheckIsPropertyWriteable(CCoreServices * pCore, CDependencyProperty * pdp);
	static HRESULT CheckAssignableForSafety(CCoreServices * pCore, CDependencyProperty * pdp, CValue * pValue);
	HRESULT GetAdjustedCValue(const xshared_ptr<XamlQualifiedObject> & inValue, const struct XamlPropertyToken & inProperty, XBOOL * pfShouldDelegateCall, CValue * * ppValue);
	HRESULT DelegateSetValue(const struct XamlTypeToken & inType, const xshared_ptr<XamlQualifiedObject> & inObj, const struct XamlPropertyToken & inProperty, const xshared_ptr<XamlQualifiedObject> & inValue, XBOOL bAllowEvents, XBOOL bBindTemplates);
	xweak_ptr<XamlSchemaContext> m_spXamlSchemaContext;
};

